package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.ProdAtta;
import com.bwie.service.ProdAttaService;
import com.bwie.mapper.ProdAttaMapper;
import com.bwie.utils.R;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 陶仕豪
 * @description 针对表【tb_prod_atta(商品附件表)】的数据库操作Service实现
 * @createDate 2025-07-19 09:43:21
 */
@Service
public class ProdAttaServiceImpl extends ServiceImpl<ProdAttaMapper, ProdAtta>
        implements ProdAttaService {
    @Autowired
    ProdAttaMapper prodAttaMapper;
    @Autowired
    HttpServletRequest request;

    @Override
    public R addAttachment(ProdAtta prodAtta) {
        String token = request.getHeader("token");
        if (token == null) {
            return R.ERROR(500, "请先登录");
        }
        String userName = Jwts.parser().setSigningKey("123456").parseClaimsJws(token).getBody().get("userName", String.class);
        prodAtta.setCreateBy(userName);
        prodAtta.setCreateTime(new Date());
        prodAttaMapper.insert(prodAtta);
        return R.OK(prodAtta);
    }


}




